package com.by.medical.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
    private MD5Util(){}

    private static final String SALT = "~#%^^@!%!@65i~";
    /**
     * 密码加密
     * @param sourceStr 原密码
     * @return 加密后的密码
     */
    public static String encodeStr(String sourceStr) {
        String encodeStr;
        try {
            sourceStr += SALT;
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(sourceStr.getBytes());
            byte[] bytes = messageDigest.digest();
            //换算
            //将字节转换成16进制里面字符
            //一个字节转换成2个16进制的字符
            BigInteger bigInteger = new BigInteger(1, bytes);
            encodeStr = bigInteger.toString(16);

        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        return encodeStr;
    }
}
